import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    name: '张三',
    age: 18,
    logOut: false
  }),
  getters: {
    getInfo(): string {
      return `${this.name}，${this.age}岁`
    }
  },
  actions: {
    setName(name: string) {
      this.name = name
    },
    setAge(age: number) {
      this.age = age
    },
    setLogOut(flag: boolean) {
      this.logOut = flag
    },
    editstore(data: any) {
      //根据传入的data更新store中的数据
      Object.assign(this, data)
    }
  },

  persist: true // 持久化
})
